var cartCount=0;
$(function(){
	if(screen.width==1920 && screen.height==1080){
		$("#jsContentContainer").addClass("real-mechine");
	}
	
	$("#jsTopAds").click(function(){
		location.href="index.html";
	});
	
	$("#jsTopAds,#jsTopAds img").height($(window).height()*0.28);
	
	$("#jsNavBar li a").click(function(){
		var that=this;
		$("#jsContentContainer").load($(this).attr("href"),function(){
			switchMenu($(that).parent().index());
		});
		return false;
	});
	$("#jsContentContainer").height($(window).height()-$("#jsTopAds").height()-$("#jsNavBar").height());
	$("#jsNavBar li:first a").click();
	
	rollAdsImgCount=$("#jsTopAds img").length;
	$("#jsTopAds div").css("width",rollAdsImgCount*$(window).width());
	setInterval(rollAdsImg,5000);
});
//滚动广告
function rollAdsImg(){
	var first=$("#jsTopAds img:first");
	first.animate({"margin-left":-$(window).width()+"px"},300,function(){
		first.appendTo($("#jsTopAds div"));
		first.css("margin-left","0");
	});
}

function switchMenu(idx){
	$("#jsNavBar li").removeClass("active");
	$("#jsNavBar li:eq("+idx+")").addClass("active");
}

function initListPage(){
	$("#jsSuperMarketCate").click(function(){
		$(this).toggleClass("scrollTop");
		$("#jsContentContainer").animate({scrollTop:$(this).is(".scrollTop")?"2000px":"0px"},500);
		var arrow=$(".cate-arrow",this).removeClass("glyphicon-chevron-down glyphicon-chevron-up");
		arrow.addClass($(this).is(".scrollTop")?"glyphicon-chevron-up":"glyphicon-chevron-down");
	});
	
	$(".product-cate a,.product-cate2 a").click(function(){
		$("#jsContentContainer")[0].scrollTop=0;
		$("#jsContentContainer").load($(this).attr("href"));
		switchMenu(1);
		return false;
	});
}

function initPackagePage(){
	$(".thumbnail img").click(function(){
		$("#jsLargeDetailImg img").attr("src",$(this).attr("src"));
		$("#jsLargeDetailImg").height($("#jsContentContainer").height()).slideDown(200);
	});
	$("#jsLargeDetailImg").click(function(){
		$("#jsLargeDetailImg").hide(100);
	});
	$(".order-buy-bar").css("bottom",$("#jsNavBar").height()+20);
	
	$("#jsBtnToAdd").click(function(){
		$("#jsBuyCout").text(++cartCount);
	});
	
	$("#jsBtnToBuy").click(function(){
		$("#jsNavBar li:last a").click();
	});
}

function initSuperMaketPage(){
	$(".btn-add").click(function(){
		$("#jsBuyCout").text(1);
	});
	
	$(".btn-buy").click(function(){
		$("#jsNavBar li:last a").click();
	});
}

function initCart(){
	$(".btn-decrease").click(function(){
		var txtCount=$(this).parent().next();
		var count=parseInt(txtCount.val(),10);
		if(count<=1){
			return;
		}
		txtCount.val(count-1);
	});
	$(".btn-increase").click(function(){
		var txtCount=$(this).parent().prev();
		var count=parseInt(txtCount.val(),10);
		txtCount.val(count+1);
	});
	
	$("#jsBtnOrder").click(function(){
		$("#jsContentContainer").load($(this).attr("href"));
	});
}

function initAddressForm(){
	$("#jsBtnSubmitOrder").click(function(){
		$("#jsContentContainer").load($(this).attr("href"));
	});
}
